
import 'package:flutter/material.dart';

class Anim1Test extends StatefulWidget {

  @override
  _Anim1TestState createState() => _Anim1TestState();
}

class _Anim1TestState extends State<Anim1Test> with SingleTickerProviderStateMixin{

  AnimationController controller1;
  Animation anim1, anim2;

  @override
  void initState() {
    super.initState();
    controller1 = AnimationController(vsync: this, duration: Duration(seconds: 3));
    anim1 = Tween(begin: 0.0, end : 255.0).animate(controller1)
    ..addListener((){
      setState(() {});
    });

    anim2 = Tween(begin: 0.0, end: 1.0).animate(controller1);
    controller1.repeat();
  }

  @override
  void dispose() {
    controller1.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Anim1Test'),
      ),
      body: RotationTransition(
        turns: anim2,
        child: Container(
          child: Center(
            child: Container(
              height: 200,
              width: 200,
              color: Colors.greenAccent,
              child: CustomPaint(
                foregroundPainter: RedRingPainter(anim1),
              ),
            ),
          ),
        ),
      ),
    );
  }
}

class RedRingPainter extends CustomPainter{

  var _paint = Paint();
  Animation anim;

  RedRingPainter(this.anim);

  @override
  void paint(Canvas canvas, Size size) {
    _paint
        ..color = Colors.redAccent
        ..strokeWidth = 2
        ..style = PaintingStyle.stroke;
    canvas.drawCircle(Offset(100, 100), anim.value * 1.5, _paint);
  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) {
    return true;
  }

}